<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<style type="text/css">
			.topic_title {
				display: block;
				font-size: 16px;
			}
			.topic_nickname {
				font-size: 14px;
				color: #3D3D3D;
				display: block;
				float: left;
			}
			.topic_in_time {
				font-size: 14px;
				color: #3D3D3D;
				display: block;
				float: right;
			}
			.ellipsis-public {	/*1溢出*/
				width: 100%;
				height: 20px;
				line-height: 20px;
			    overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 1;	
				-webkit-box-orient: vertical;
			}
			.ellipsis-public-2 {	/*2溢出*/
				width: 100%;
				height: 40px;
				line-height: 20px;
			    overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;	
				-webkit-box-orient: vertical;
			}
		</style>
	</head>

	<body>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<a href="#">
							<img class="mui-media-object mui-pull-left" src="" width="50" id="avatar">
							<div class="mui-media-body">
								<span id="nickname"></span>
								<p class='mui-ellipsis' id="score"></p>
							</div>
						</a>
					</li>
				</ul>
				<ul class="mui-table-view" id="topics_ul">
				</ul>
				<ul class="mui-table-view" id="collets_ul">
				</ul>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/zepto.min.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript" charset="utf-8">
			var index;
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					}
				}
			});
			mui.plusReady(function(){
				//获得主页面webview引用；
				index = plus.webview.currentWebview().opener();
				if(isLogin()) {
					mui.fire(index, "showLogout");
					mui.fire(index, "hideCreateTopic");
				}
				initData();
			});
			
			function initData() {
				mui.ajax({
					type: "post",
					url: _baseUrl + "/api/user",
					data: {
						token: plus.storage.getItem(_user_token)
					},
					async: true,
					dataType: "json",
					success: function(data) {
						var user = data.detail.user;
						var topics = data.detail.topics;
						var collects = data.detail.collects;
						$("#avatar").attr("src", user.avatar);
						$("#nickname").html(user.nickname);
						$("#score").html("积分：" + user.score);
						
						var topics_ul = $("#topics_ul");
						topics_ul.html('<li class="mui-table-view-divider">最近话题</li>');
						mui.each(topics, function(index, _data){
							var inTime = formatDateTime(_data.in_time);
							var html = '<li class="mui-table-view-cell"><a href="javascript:topic_detail(\''+_data.id+'\')">'+
										'<span class="topic_title ellipsis-public">'+_data.title+'</span>'+
										'<span class="topic_nickname">'+plus.storage.getItem(_user_nickname)+'</span>'+
										'<span class="topic_in_time">'+inTime+'</span>'+
										'</a></li>';
							topics_ul.append(html);
						});
						var collets_ul = $("#collets_ul");
						collets_ul.html('<li class="mui-table-view-divider">收藏话题</li>');
						mui.each(collects, function(index, _data){
							var inTime = formatDateTime(_data.in_time);
							var html = '<li class="mui-table-view-cell"><a href="javascript:topic_detail(\''+_data.id+'\')">'+
										'<span class="topic_title ellipsis-public">'+_data.title+'</span>'+
										'<span class="topic_nickname">'+_data.nickname+'</span>'+
										'<span class="topic_in_time">'+inTime+'</span>'+
										'</a></li>';
							collets_ul.append(html);
						});
						mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					}
				});
			}
			
			function pulldownRefresh() {
				initData();
			}
		</script>
	</body>

</html>